package com.example.demo.config;

import com.example.demo.common.SessionUtil;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class LoginIntercept implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        // 判断是否登录
        if (SessionUtil.getUser(request) != null) {
            return true;
        } else {
            response.sendRedirect("/login.html");
            return false;
        }
    }
}
